﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Manage_Update_waitPriceState : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAdmin);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            datashow();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)　//修改Change_price_state　状态
    {
        Db db = new Db();
        if( Button1.Text == "调整价格已关闭")
        {
            db.Command("update Project set Change_price_state=1 where ProjectId="+Request.Params["ProjectId"].ToString());
        }
        else
        {
           db.Command("update Project set Change_price_state=0 where ProjectId=" + Request.Params["ProjectId"].ToString());
        }
       
        db.Close();
        datashow();
       
    }

    private void datashow()
    {
        Db db = new Db();
        System.Data.IDataReader dr;
        dr = db.DataReader("select Change_price_state from Project where ProjectId=" + Request.Params["ProjectId"].ToString());
        dr.Read();
        if (SysFun.ToInt(dr["Change_price_state"].ToString()) == 0)
        {
            Button1.Text = "调整价格已关闭";
            Button1.ForeColor = System.Drawing.Color.Red;
            Button2.Enabled = false;
        }
        else
        {
            Button1.Text = "调整价格已开启";
            Button1.ForeColor = System.Drawing.Color.Snow;
            Button2.Enabled = true;
        }
        dr.Close();
        dr.Dispose();
        db.Close();
    }
    protected void Button2_Click(object sender, EventArgs e) //调整中标价格
    {
        string  str = "", strSql,SupplyGoodsId="";
        int nNumber = 0;
        Db db = new Db();
        System.Data.IDataReader dr;
        strSql = "select SupplyGoodsId from SupplyPlan_Goods where waitState=1";
        dr = db.DataReader(strSql);
        while (dr.Read())
        {
            nNumber++;
            SupplyGoodsId += SysFun.ToTrim(dr["SupplyGoodsId"])+",";
        }
        dr.Close();
        dr.Dispose();
        if (SupplyGoodsId.Length > 2)
        { 
            SupplyGoodsId = SupplyGoodsId.Remove(SupplyGoodsId.Length - 1);
            str = "update SupplyPlan_Goods set historyPrice =convert(varchar(1000),historyprice) +'|'+ convert(varchar(1000),BidPrice) where supplyGoodsId in (" + SupplyGoodsId + ")";
            str += " update SupplyPlan_Goods set historytime =convert(varchar(1000),historytime) +'|'+ convert(varchar(1000),getdate()) where supplyGoodsId in (" + SupplyGoodsId + ")";
            str += " update SupplyPlan_Goods set BidPrice=LatestPrice where supplyGoodsId in (" + SupplyGoodsId + ")";
            str += " update SupplyPlan_Goods set LatestPrice='',waitState=0 where supplyGoodsId in (" + SupplyGoodsId + ")";
            str += " update tra_HosptaiPurchase_SupplyPlan_Goods set tra_HosptaiPurchase_SupplyPlan_Goods.PurchasePrice=bb.BidPrice from tra_HosptaiPurchase_SupplyPlan_Goods ,tra_HosptaiPurchase_SupplyPlan_Goods as bb where tra_HosptaiPurchase_SupplyPlan_Goods.supplyGoodsId in (" + SupplyGoodsId + ")";
            db.Command(str);
           
            Response.Write("<script>alert('中标价格修改成功！！！影响" + nNumber.ToString() + "条记录');</script>");
            Button2.Enabled = false;
        }
        else
        {
            Response.Write("<script>alert('中标价格已修改！');</script>");
        }

        db.Close();

        
    }
    
}
